from strategy.StrategyTemplate import StrategyTemplate
from utils.jsl_data_map import default_columns
# from database.lhjy import engine
from strategy import strategy_filter
# from utils.simple_utls import code_fix
import pandas as pd


class Dao5(StrategyTemplate):
    """
    三低进攻策略:
        三低进攻策略

    """
    def __init__(self):
        super(Dao5, self).__init__()
        self.strategy_name = "三低进攻策略"
        self.strategy_descrption = "三低进攻策略"

    def run(self):
        self.data = strategy_filter.filter_base(self.data)
        self.data = self.data[self.data['现价'] < 130]
        self.data = self.data[self.data['溢价率'] < 40]
        self.data = self.data[self.data['剩余规模'] < 3.5]
        self.data = self.data[self.data['换手率'] > 10]
        method = 'first'
        self.data['rank1'] = self.data['溢价率'].rank(method=method, ascending=True)
        self.data['rank2'] = self.data['现价'].rank(method=method, ascending=True)
        self.data['rank3'] = self.data['剩余规模'].rank(method=method, ascending=True)
        # self.data_tool['rank123'] = self.data_tool['rank1'] + self.data_tool['rank2'] + self.data_tool['rank3']
        # self.data_tool['rank0'] = self.data_tool['rank123'].rank(method=method, ascending=True)
        self.data['rank4'] = self.data['换手率'].rank(method=method, ascending=False)
        # self.data_tool['rank'] = self.data_tool['rank0'] + self.data_tool['rank4']
        self.data['rank'] = self.data['rank1'] + self.data['rank2'] + self.data['rank3'] + self.data['rank4']
        self.data = self.data.sort_values(by='rank', ascending=True)

        # 获得默认列
        default_columns.extend(['rank'])
        self.data = self.data[default_columns]
        # 清掉原来的索引
        self.data.reset_index(inplace=True, drop=True)


if __name__ == '__main__':
    ins = Dao5()
    ins.topN = 20
    ins.test()